import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import 'index.dart';
import 'widgets/index.dart';

class SupportPage extends GetView<SupportController> {
  const SupportPage({super.key});

  // 主视图
  Widget _buildView() {
    return Column(
      children: [
        // 帮助与反馈
        _buildListItem(
          title: "帮助与反馈",
          onTap: () {
            // 确保SupportController已经注入
            if (!Get.isRegistered<SupportController>()) {
              Get.put(SupportController());
            }
            Get.to(() => const FeedbackView());
          },
        ),
        
        const Divider(height: 1),
        
        // 联系客服
        _buildListItem(
          title: "联系客服",
          onTap: () {
            // 确保SupportController已经注入
            if (!Get.isRegistered<SupportController>()) {
              Get.put(SupportController());
            }
            Get.to(() => const CustomerServiceView());
          },
        ),
      ],
    );
  }
  
  // 列表项
  Widget _buildListItem({
    required String title, 
    required VoidCallback onTap
  }) {
    return InkWell(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.normal,
              ),
            ),
            const Icon(
              Icons.arrow_forward_ios,
              size: 16,
              color: Colors.grey,
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SupportController>(
      init: SupportController(),
      id: "support",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("反馈与客服"),
            backgroundColor: Colors.white,
            foregroundColor: Colors.black,
            elevation: 0,
            systemOverlayStyle: const SystemUiOverlayStyle(
              statusBarColor: Colors.transparent,
              statusBarIconBrightness: Brightness.dark,
            ),
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
